# TABLES -----------------------------------------------------------------------
#   This file outputs the tables displayed in the paper and in the appendix. 

# Create directory to save plots -----------------------------------------------
#   If the directory already exists, this function will display a warning
path <- file.path(getwd(), paste0("tables/", experiment))
dir.create(path, showWarnings = FALSE)

# OLS Models (Main, Missing Data, and Interaction Terms) -----------------------
get_table(list("Base" = at_ln$Main$Base, 
               "Adjusted" = at_ln$Main$Adjusted, 
               "Full" = at_ln$Main$Full,
               "Base" = at_ln$DropNA$Base, 
               "Adjusted" = at_ln$DropNA$Adjusted, 
               "Full" = at_ln$DropNA$Full,
               "Base" = at_ln$Interaction$Base, 
               "Adjusted" = at_ln$Interaction$Adjusted, 
               "Full" = at_ln$Interaction$Full), 
          type = "ols", x = "at") |>
  group_tt(j = list("Main" = 2:4, 
                    "Missing Data" = 5:7,
                    "Interaction Terms" = 8:10)) |>
  theme_tt("resize", width = .95) |>
  save_tt(paste0(path, "/_tbl-at-ols.tex"), overwrite = TRUE)

get_table(list("Base" = rt_ln$Main$Base, 
               "Adjusted" = rt_ln$Main$Adjusted, 
               "Full" = rt_ln$Main$Full,
               "Base" = rt_ln$DropNA$Base, 
               "Adjusted" = rt_ln$DropNA$Adjusted, 
               "Full" = rt_ln$DropNA$Full,
               "Base" = rt_ln$Interaction$Base, 
               "Adjusted" = rt_ln$Interaction$Adjusted, 
               "Full" = rt_ln$Interaction$Full), 
          type = "ols", x = "rt") |>
  group_tt(j = list("Main" = 2:4, 
                    "Missing Data" = 5:7,
                    "Interaction Terms" = 8:10)) |>
  theme_tt("resize", width = .95) |>
  save_tt(paste0(path, "/_tbl-rt-ols.tex"), overwrite = TRUE)

# Logistic and ordered logistic models -----------------------------------------
get_table(list("Base" = at_lg$Main$Base, 
               "Adjusted" = at_lg$Main$Adjusted, 
               "Full" = at_lg$Main$Full, 
               "Base" = at_or$Main$Base, 
               "Adjusted" = at_or$Main$Adjusted, 
               "Full" = at_or$Main$Full), 
          type = "log", x = "at") |>
  group_tt(j = list("Logistic" = 2:4, "Ordered Logistic" = 5:7)) |>
  save_tt(paste0(path, "/_tbl-at-log.tex"), overwrite = TRUE)

get_table(list("Base" = rt_lg$Main$Base, 
               "Adjusted" = rt_lg$Main$Adjusted, 
               "Full" = rt_lg$Main$Full,
               "Base" = rt_or$Main$Base, 
               "Adjusted" = rt_or$Main$Adjusted, 
               "Full" = rt_or$Main$Full), 
          type = "log", x = "rt") |>
  group_tt(j = list("Logistic" = 2:4, "Ordered Logistic" = 5:7)) |>
  save_tt(paste0(path, "/_tbl-rt-log.tex"), overwrite = TRUE)